<br>
<br>
<div class="row">
    <div class="col-xs-12 col-md-12">
        <div class="grid simple">
            <div class="grid-body no-border">
                <form id="edit-role">
                    <div class="row">
                            <div class="row form-row">
                                <div class="col-xs-4 col-md-4">
                                    <label class="form-label">用户名</label>
                                    <h4><?= $admin['username'] ?></h4>
                                </div> 
                            </div>
                            <br>
                            <div class="row form-row">
                                <div class="col-xs-4 col-md-4">
                                    <label class="form-label">昵称</label>
                                    <h4><?= $admin['nickname'] ?></h4>
                                </div> 
                            </div>
                            <br>
                            <div class="row form-row">
                                <div class="col-xs-8 col-md-8">
                                    <label class="form-label">角色</label>
                                </div> 
                            </div> 

                            <div class="row form-row">
                                    <? if($roles):?>
                                        <? foreach($roles as $r):?>
                                        <div class="col-xs-3 col-md-3">
                                            <div class="checkbox check-success">
                                                <? $id = "role-{$r['role_id']}" ?>
                                                <? if(is_array($admin['roles']) && isset($admin['roles'][$r['role_id']])): ?>
                                                    <? $checked = 'checked="checked"' ?>
                                                <? else: ?>
                                                    <? $checked = '' ?>
                                                <? endif ?>
                                                <input type="checkbox" <?= $checked ?> value="<?= $r['role_id']?>" name="roles[]" id="<?= $id ?>">
                                                <label for="<?= $id ?>"><?= $r['name']?></label>
                                            </div>
                                        </div>
                                        <? endforeach ?>
                                    <? endif ?>
                            </div>
                    </div>
                      
                    <div class="form-actions">  
                        <div class="pull-left">
                            <button class="btn btn-success btn-cons" type="button" onclick="$.Edit_role.submit()">
                                <i class="icon-save"></i>&nbsp;保存</button>
                            </button>
                            <button class="btn btn-white btn-cons" type="button" onclick="$.T.reset_form(this)">
                                重置
                            </button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    $.Edit_role = {
        admin_id: <?= $admin['admin_id']?>,
        submit: function()
        {
            var form   = $('#edit-role');
            var params = form.serializeArray();
            var flag   = false;

            console.log(params);
            for (var i in params)
            {
                if(params[i]['name'] == 'roles[]')
                {
                    flag = true;
                    break;
                }
            }
            if(flag === true)
            {
                form
                    .attr('action', $.G.domain+'admin/edit_role/'+$.Edit_role.admin_id)
                    .attr('method', 'POST')
                    .submit();
            }
            else
            {
                $.T.confirm("您没有选择任何用户，确认要删除该用户所有角色吗？", function(){
                    form
                    .attr('action', $.G.domain+'admin/del_role/'+$.Edit_role.admin_id)
                    .attr('method', 'POST')
                    .submit();
                });
            }
        }
    }
</script>